package com.xu.demo.factoryPattern;

/**
 * 简单工厂模式类
 */
public class SimpleFactoryPattern {

    public static Phone create(String name) {
        //根据输入对象名称判断返回相匹配的对象
        if("IPhone".equals(name)) {
            //返回对象
            return new IPhone();
        }else if("MiPhone".equals(name)) {
            return new MiPhone();
        }
        return null;
    }


    public static void main(String[] args) {
        Phone phone = SimpleFactoryPattern.create("IPhone");
        phone.call();

        Phone phone2 = SimpleFactoryPattern.create("MiPhone");
        phone2.call();
    }
}


